<?
        session_start();
		if(isset($_POST['card_num']))
        {
			require_once 'inc/anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct.
			$transaction = new AuthorizeNetAIM('884M4cJLxbKr', '28h7Td59Pg592zBE');
		   
			$transaction->amount = $_POST['price'];
			$transaction->card_num = $_POST['card_num'];
			$transaction->exp_date = $_POST['exp_date'];
		   
			$response = $transaction->authorizeAndCapture();
			header("Location: index.php");
        }

		require("inc/functions.php");
	 	require_once('inc/facebook.php');
	 	$facebook = new Facebook(array(
	 	'appId' => '266106703516634',
	 	'secret' => '57f64882d938b38d36f88185fc2fd78d'
		));
		
		$fbUser = $facebook->getUser();
		
		if(isset($_POST['login']))
			LoginUser($_POST);
?>

<?php
	include("inc/views/header_view.php");
	include("inc/views/navbar_view.php");
?>

<body>


	<div class="container">
    <? if($fbUser): ?>
		<img src="http://graph.facebook.com/<?=$fbUser?>/picture" />
	 	<a href="<?=$facebook->getLogoutUrl()?>">Log Out</a>
	 	<? else: ?>
	 	<a href="<?=$facebook->getLoginUrl(array('scope' => 'read_stream, friends_likes'))?>">
	 	Log in with Facebook
		</a>
	<? endif; ?>
  		<div class="row">
        	<form class="well" method="post" action="?">
            	Price: <input type="number" name="price" /> <br />
                Credit Card Number: <input type="text" name="card_num" /> <br />
                Experation Date: <input type="text" name="exp_date" />
                <input type="submit" value="Buy Now" />
            </form>
        </div>
    </div>
<?php
	include("inc/views/footer_view.php");
?>
<?
        function curl_get($path, $method="GET", $data=null)
        {
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_HEADER, FALSE);
                curl_setopt($curl, CURLOPT_TIMEOUT, 20);
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // no echo, just return result
                curl_setopt($curl, CURLOPT_USERAGENT, 'SUNY New Paltz web course');
                if ($method === 'POST') {
                        curl_setopt($curl, CURLOPT_POST, TRUE);
                        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
                }elseif(!empty($data)){
                        if(strpos($path, '?') === false)
                                $path .= '?';
                        else
                                $path .= '&';
                        $path .= http_build_query($data);
                }
                //echo $path;
                curl_setopt($curl, CURLOPT_URL, $path);

                return curl_exec($curl);
        }
?>

